#include <iostream>
#include <vector>

using namespace std;

const int M = 1 << 10;

int n, m;
int g[M];
int cnt[M];
int f[2][M][M];
vector<int> state;

bool check(int x) {
    return (!(x & x >> 1) && !(x & x >> 2));
}

int count(int state) {
    int res = 0;
    for (int i = 0; i < m; ++ i) res += (state >> i & 1);
    return res;
}

int main() {
    cin >> n >> m;
    
    for (int i = 1; i <= n; ++ i)
        for (int j = 0; j < m; ++ j) {
            char cc;
            cin >> cc;
            g[i] += (cc == 'H') << j;
        }
    
    
    for (int i = 0; i < 1 << m; ++ i) 
        if (check(i)) {
            state.push_back(i);
            cnt[i] = count(i);
        }
    
    for (int i = 1; i <= n + 2; ++ i)
        for (int j = 0; j < state.size(); ++ j)
            for (int k = 0; k < state.size(); ++ k)
                for (int u = 0; u < state.size(); ++ u) {
                    int a = state[j], b = state[k], c = state[u];
                    if ((a & b) | (a & c) | (b & c)) continue;
                    if (g[i] & b) continue;
                    f[i & 1][j][k] = max(f[i & 1][j][k], f[i - 1 & 1][u][j] + cnt[b]);
                }
                
    cout << f[n + 2 & 1][0][0] << endl;
    
    return 0;
}